package cn.lg.soar.cloud.core.config;

import cn.lg.soar.cloud.core.feign.fallback.OperationLogApiFallbackFactory;
import cn.lg.soar.common.util.data.DataUtil;
import feign.RequestInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author luguoxiang 469599794@qq.com
 * @Date: 2024/2/23 16:30
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ImportAutoConfiguration({
        CloudProperties.class,
        ResourceApiImpl.class,
        FeignRequestInterceptor.class,
        OperationLogApiFallbackFactory.class,
        FeignRequestConfig.class,
        CloudExceptionHandler.class,
})
@Configuration
public class AutoConfiguration {
    static {
        CloudExceptionHandler.init();
    }

    @Autowired
    private CloudProperties properties;

    @Bean
    public RequestInterceptor feignRequestInterceptor() {
        if (DataUtil.isValuable(properties.getSecret())) {
            return new FeignSecretRequestInterceptor(properties);
        }
        return new FeignRequestInterceptor();
    }

}
